#include <iostream>
#include <vector>

const int N = 1e6 + 5;
const int inf = 1e9;

int n, q;
int a[N], pre[N];
std::pair<int, int> mi[21][N], mx[21][N];
int lg2[N];

struct Node {
	int l, r, sum, ans;
	Node(int l, int r, int sum, int ans) : l(l), r(r), sum(sum), ans(ans) {}
	Node() {}
} t[N << 2];

Node merge(const Node& x, const Node& y) {
	return Node(std::max(x.l, x.sum + y.l), std::max(y.r, y.sum + x.r), x.sum + y.sum, std::max(std::max(x.ans, y.ans), x.r + y.l));
}

inline void build(int o, int l, int r) {
	if(l == r) {
		t[o] = Node(a[l], a[l], a[l], a[l]);
		return;
	}
	int mid = l + r >> 1;
	build(o << 1, l, mid);
	build(o << 1 | 1, mid + 1, r);
	t[o] = merge(t[o << 1], t[o << 1 | 1]);
}

inline Node query(int o, int ql, int qr, int l, int r) {
	if(ql > qr) return Node(0, 0, 0, 0);
	if(ql <= l && r <= qr) {
		return t[o];
	}
	int mid = l + r >> 1;
	Node res(-inf, -inf, 0, -inf);
	if(ql <= mid) res = merge(res, query(o << 1, ql, qr, l, mid));
	if(mid < qr) res = merge(res, query(o << 1 | 1, ql, qr, mid + 1, r));
	return res;
}

inline std::pair<int, int> querymi(int l, int r) {
	int i = lg2[r-l+1];
	return std::min(mi[i][l], mi[i][r-(1<<i)+1]);
}

inline std::pair<int, int> querymx(int l, int r) {
	int i = lg2[r-l+1];
	//std::cerr << "q = " << i << " " << l << " " << (r - (1 << i) + 1) << "\n";
	return std::max(mx[i][l], mx[i][r-(1<<i)+1]);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("good.in", "r", stdin);
	std::freopen("good.out", "w", stdout);

	std::cin >> n >> q;
	for(int i = 1; i <= n; ++i) {
		char ch; std::cin >> ch;
		a[i] = ch == '1' ? 1 : -1;
		pre[i] = pre[i-1] + a[i];
	}
	for(int i = 2; i <= n + 1; ++i) lg2[i] = lg2[i >> 1] + 1;
	for(int i = 0; i <= n + 1; ++i) mi[0][i] = mx[0][i] = std::make_pair(pre[i], i);
	for(int j = 1; j <= 20; ++j) {
		for(int i = 0; i <= n + 1; ++i) {
			if(i + (1 << j) - 1 > n + 1) break;
			mi[j][i] = std::min(mi[j-1][i], mi[j-1][i+(1<<j-1)]);
			mx[j][i] = std::max(mx[j-1][i], mx[j-1][i+(1<<j-1)]);
		}
	}
	build(1, 1, n);
	int ans = 0;
	while(q--) {
		int l, r; std::cin >> l >> r;
		auto e1 = querymi(l-1, r);
		int res = 0;
		/*
		if(e1.second < e2.second) {
			res = pre[l-1] - e1.first + e2.first - pre[r];
		} else {
		*/
		res += pre[l-1] - e1.first;
		int mx = query(1, l, e1.second, 1, n).ans;
		if(e1.second >= l) mx = std::max(mx, 1);
		mx = std::max(mx + e1.first, querymx(e1.second, r).first);
		res += mx - pre[r];
		ans ^= res;
	}
	std::cout << ans << "\n";

	return 0;
}
